/**
 * Copyright (c) 2008, Julien PORTALIER
 * http://featherphp.googlecode.com/
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */
var trans = {
	translations: {},
	lang: null,
	
	init: function()
	{
		this.lang = $$('html').get('xml:lang');
		if (!this.lang)
		{
			this.lang = $$('html').get('lang');
			if (!this.lang) {
				this.lang = $$('meta[name=language]').get('content');
			}
		}
		if (trans.lang) {
			Asset.javascript('/js/locales/messages.' + this.lang + '.js');
		}
	},
	
	/**
	 * Adds translations.
	 * @param {String} context
	 * @param {String} translations
	 */
	add: function(context, translations)
	{
		if (context)
		{
			if (this.translations['_ctx_' + context]) {
				$extend(this.translations['_ctx_' + context], translations);
			}
			else {
				this.translations['_ctx_' + context] = translations;
			}
		}
		else
		{
			$extend(this.translations, translations);
		}
	},
	
	/**
	 * Translates a String.
	 * 
	 * @return String
	 * @param {String} msgid
	 */
	t: function(msgid)
	{
		return this.translations[msgid] ? this.translations[msgid] : msgid;
	},
	
	/**
	 * Translates a String in a given context.
	 * 
	 * @return String
	 * @param {String} context
	 * @param {String} msgid
	 */
	ct: function(context, msgid)
	{
		return this.translations['_ctx_' + context] ? (this.translations['_ctx_' + context][msgid] ?
			this.translations['_ctx_' + context][msgid] : msgid) : msgid;
	}
}

//trans.init();
